package com.googlecode.cswish.util;

import java.math.BigInteger;

public class SimpleEncryptUtil {

	private final static String SEED = "0123912432163123112514231";
	private final static int RADIX = 16;
	
	public static String encrypt(String text) {  
        if (text == null)  
            return "";  
        if (text.length() == 0)  
            return "";  
  
        BigInteger bi_text = new BigInteger(text.getBytes());  
        BigInteger bi_r0 = new BigInteger(SEED);  
        BigInteger bi_r1 = bi_r0.xor(bi_text);  
        return bi_r1.toString(RADIX);  
    }
	
	public static String decrypt(String encrypted) {  
        if (encrypted == null)  
            return "";  
        if (encrypted.length() == 0)  
            return "";
        
        BigInteger bi_confuse = new BigInteger(SEED);
        try {  
            BigInteger bi_r1 = new BigInteger(encrypted, RADIX);  
            BigInteger bi_r0 = bi_r1.xor(bi_confuse);  
  
            return new String(bi_r0.toByteArray());  
        } catch (Exception e) {
            return "";  
        }  
    }
}
